package com.example.idemfactor.sdk.aspect;

import com.example.idemfactor.sdk.annotations.Idemfactor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

public class IdemInterceptor extends IdemAspectSupport implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        //方法
        Method method = methodInvocation.getMethod();

        //参数
        Object[] args = methodInvocation.getArguments();

        //目标对象
        Object target = methodInvocation.getThis();

        //执行业务逻辑 返回值表示执行业务方法后返回的结果
        Object invoke = methodInvocation.proceed();

        // 获取注解信息
        Idemfactor annotation = method.getAnnotation(Idemfactor.class);

        //无注解直接放行
        if (annotation == null) {
            return invoke;
        }

        return execute(invoke,target,method,args);
    }

}
